<template>
	<view class="is_auth" style="background-image: url(https://cdnauth.dreamyuewen.com/images/is_auth_bg.png);">
		<u-navbar :autoBack="true" bgColor="rgba(0,0,0,0)" :fixed="true" @click-left="$back" ></u-navbar>
		
		<view class="navs">
			<view class="top">实名认证</view>
			<view class="bottom">如需更换实名认证请联系客服</view>
		</view>
		<view class="centers">
			<view class="top">
				<view class="one">姓名</view>
				<view class="tow">
					<!-- <input type="text" style="height: 40px;line-height:40px;text-align: right;color: #999;" v-model="card_msg.id_name"> -->
					<text style="height: 40px;line-height:40px;text-align: right;color: #999;">{{card_msg.id_name}}</text>
				</view>
			</view>
			<view class="bottom">
				<view class="one">身份证号</view>
				<view  class="tow">
					<!-- <input type="text" style="height: 40px;line-height:40px;text-align: right;color: #999;" v-model="card_msg.id_card"> -->
					<text style="height: 40px;line-height:40px;text-align: right;color: #999;">{{card_msg.id_card}}</text>
				</view>
			</view>
		</view>
		
		<view class="ti" v-if="userInfo.is_auth==0" @click="savepic()">
			保存
		</view>
		<view class="text">
			<!-- 实名认证需要输入您的姓名和身份证号，并且采集面<br>
			部信息来确保头像、身份证都是本人。<br>
			每个身份证只能认证一个账号，详见<span class="zehngc" @click.stop="goToOtherxie(14)">《隐私政策》</span> -->
			恭喜您认证成功，享受平台更多权益。
		</view>
	</view>
</template>
<script>
	export default { 
		data() {
			return {
				userInfo: {},
				card_msg:{
					id_name: '',
					id_card: ''
				}
			}
		},
		onShow() {
			this.getUserInfo()
		},
		onLoad() {
			 	
		},
		methods: {
			savepic(){
				this.$api.default.request('user/idcard_save',this.card_msg).then((res) => {
					if (res.code) {
						this.$common.errorToShow(res.msg)
						setTimeout(function(){
							uni.navigateBack({
							  delta: 2
							})
							
						}, 500); 
					} else {
						this.$common.errorToShow(res.msg)
					}
				})
				
			},
			bindPickerChange: function(e) {
			            console.log('picker发送选择改变，携带值为', e.detail.value)
			            this.index = e.detail.value
						this.saveUser({
							'sex': this.index
						})
			},
			getUserInfo() {
				this.$api.default.request('user/userInfo').then((res) => {
					if (res.code) {
						this.userInfo = res.user
						this.index = res.user.sex?res.user.sex:0
						
						this.card_msg = {
							id_card: res.user.id_card,
							id_name: res.user.id_name
						}
					} else {
						this.$common.errorToShow(res.msg)
					}
				})
			},
			onChooseAvatar(e) {
				this.$common.uploadImg(e.detail.avatarUrl, (data) => {
					if (data) {
						this.saveUser({
							'pic': data
						})
					}
				})
			},
			bindNick(e) {
				console.log(e)
				if (e.detail.value != this.userInfo.username) {
					this.userInfo.username = e.detail.value
					this.saveUser({
						'username': this.userInfo.username
					})
				}
			},
			saveUser(data) {
				this.$api.default.request('user/saveUser', data).then((res) => {
					if (res.code == 1) {
						this.userInfo = res.user
						this.$common.successToShow(res.msg)
					} else {
						this.$common.errorToShow(res.msg)
					}
				})
			},
			// 头像弹框
			open() {
				
			},
			close() {
				this.show = false
			},
			// 生日
			 bindDateChange: function(e) {
				this.date = e.detail.value
				this.saveUser({
					'birthday': e.detail.value
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: rgba(242, 245, 242, 1);
	}
	.is_auth {
		height: 100vh;
		background-size: 100%;
		padding-top: 100px;
		box-sizing: border-box;
		.navs{
			float:  left;
			width:86%;
			margin-left: 7%;
			.top{
				padding-top:60rpx;
				font-size: 40rpx;
				font-weight: 700;
			}
			.bottom{
				font-family: Source Han Sans CN;
				font-size:24rpx;
				color: #999999;
				margin-top: 5px;
			}
		}
		
		.centers{
			margin-top: 15px;
			float:  left;
			background: #fff;
			width:84%;
			border-radius: 0.5em;
			margin-left: 8%;
		
			font-size: 14px;
			.top{
				height: 40px;
				line-height: 40px;;
				float: left;
				width: 100%;
				padding:  0 10px;
				box-sizing: border-box;
				border-bottom: 1px solid rgba(153, 153, 153, 0.1);
	
				.one{
					font-weight: 700;
					float: left;
					width: 40%;
				}
				.tow{
					 float: right;
					 width: 60%;
					 text-align: right;
					 color: #999;
				}
			}
			.bottom{
				height: 40px;
				line-height: 40px;
				float: left;
				width: 100%;
				padding:  0 10px;
				box-sizing: border-box;
				.one{
					font-weight: 700;
					float: left;
					width: 40%;
					
				}
				.tow{
					
					float: right;
					text-align: right;
					width: 60%;
					color: #999;
				}
			}
			
		}
		.ti {
			
			
			float: left;
			width: 84%;
		
			height: 86rpx;
			border-radius: 8px;
			line-height: 86rpx;
	
			margin-left: 8%;
			margin-top: 20px;
			opacity: 1;
			background: #45C4B0;
			font-size: 32rpx;
			font-weight: bold;
			text-align: center;
			letter-spacing: 0em;
			color: #FFFFFF;
		}
		.text{
			float: left;
			width: 82%;
			margin-left: 9%;
			margin-top: 10px;
			color: #999;
			font-size: 12px;
			text-align: center;
			.zehngc{
				color: #45C4B0;
			}
		}
	}
</style>